<?php

namespace App\Models\Chain\PointCash;


use App\Models\Chain\AbstractHandler;
use App\Helpers\Logger\SLogger;
use App\Models\Chain\PointCash\CreateCreditLogAction;
use DB;

/**
 *
 */
class DoCreditCashHandler extends AbstractHandler
{
    #外部传参

    private $params = array();

    public function __construct($params)
    {
        $this->params = $params;
        $this->setSuccessor($this);
    }

    /**
     * @return mixed]
     */

    //1.查看可兑换积分
    //2.修改积分表
    //3.生成积分兑换流水表
    //4.插入积分日志表
    //5.插入现金流水表
    //6.修改现金表

    public function handleRequest()
    {
        $result = ['error' => '积分兑换出错啦', 'code' => 10001];

//	    DB::beginTransaction();
//	    try
//	    {
        $this->setSuccessor(new CheckCreditAction($this->params));
        $result = $this->getSuccessor()->handleRequest();
        if (isset($result['error'])) {
//            DB::rollback();

//            SLogger::getStream()->error('提现失败-try');
            SLogger::getStream()->error($result['code']);
        }
//		    else
//		    {
//			    DB::commit();
//		    }
//	    }
//	    catch (\Exception $e)
//	    {
//		    DB::rollBack();
//
//		    SLogger::getStream()->error('提现失败-catch');
//		    SLogger::getStream()->error($e->getMessage());
//	    }
        return $result;
    }

}
